<!-- 健康填报列表历史 -->
<template>
	<view class="container">
		<template v-if="empty">
		    <view class="tabsContent">
				<u-empty mode="data" width="280" height="280" textSize="28"
		     icon="http://cdn.uviewui.com/uview/empty/data.png" text="您未添加健康数据"></u-empty>
		    </view>
		</template>
		<template v-else>
			<view class="formBox" v-for="(item,index) in serviceList">
				<view>
					<!-- <view class="visitor-num">访客登记{{index+1}}</view> -->
					<view class="line">
						<view class="line-title">姓名：</view>
						<u--text :size="26" color="#999999" mode="name" :text="item.userName"></u--text>
					</view>
					<view class="line">
						<view class="line-title">联系电话：</view>
						<u--text :size="26" color="#999999" mode="phone" :text="item.phonenumber"></u--text>
					</view>
					<view class="line">
						<view class="line-title">填写时间：</view>
						<u--text :size="26" color="#999999" :text="item.creatTime"></u--text>
					</view>
					<view class="line">
						<view class="line-title">体温：</view>
						<u--text :size="26" color="#999999" :text="item.bodyTemperature+'℃'"></u--text>
					</view>
				</view>
				<u-gap height="16"></u-gap>
				<view class="line line-btn">
					<u-button @click="modifyService(item)" type="primary" style="width: 40%; height: 100%;" :plain="true" text="编辑"></u-button>
					<u-button @click="delService(item)" type="error" style="width: 40%; height: 100%;" :plain="true" text="删除" ></u-button>
				</view>
			</view>
		</template>
		<view style="width:100% ;height:110rpx ;">
			
		</view>
		<view class="bottomBtn">
			<u-button @click="addService" type="primary" text="添加健康填报"></u-button>
		</view>
		<u-modal :show="show" content='今日你已提交过健康填报了,请明日再来!' @confirm="show = false"></u-modal>
		<u-modal :show="deleteShow" :title="deleteTitle" showCancelButton buttonReverse :zoom="false"
			:closeOnClickOverlay="true" @confirm="deleteConfirm" @cancel="deleteShow = false"
			@close="deleteShow = false "></u-modal>
	</view>
</template>

<script>
	import api from "@/api/api.js"
	export default {
		name: '',
		components: {},
		data() {
			return {
				yes: null,
				show:false,
				pageNum:1,
				pageSize:5,
				serviceList:[],
				empty:false,//是否为空
				num:null,//条数
				deleteShow: false,
				deleteTitle: '是否确认删除',
				deleteId: null,
				
			}
		},
		created() {
			this.getServiceList()
			this.getyeshealth()
		},
		mounted() {},
		destroyed() {},
		methods: {
			// 获取填写历史数据
			getServiceList(){
				let userInfo = uni.getStorageSync('userInfo')
				let data={
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					// userId:14
					userId:userInfo.id
				}
				api.getReport(data).then(res=>{
					console.log(res)
					if(res.data.code==601){
						this.empty=true
					}else if(res.data.code===200){
						this.serviceList = this.serviceList.concat(res.data.rows)
						this.num=Math.ceil(res.data.total/this.pageSize)//总条数除一页多少条向上取整
						this.pageNum++
						if(this.serviceList.length<1){
							this.empty=true
						}else{
							this.empty=false
						}
					}
				})
			},
			//查询当天是否已提交
			getyeshealth() {
				let userInfo = uni.getStorageSync('userInfo')
				api.yeshealth({
					userId: userInfo.id
				}).then(res => {
					this.yes = res.data.data
					console.log('判断', this.yes)
				})
			},
			// 添加健康填报
			addService(){
				if(this.yes===1){
					this.show=true
				}else{
					uni.$u.route('/pages/service/addService');
				}
			},
			// 修改填报
			modifyService(item){
				console.log(item)
				uni.$u.route({
					type: "navigateTo",
					url: '/pages/service/modifyService',
					params: {
						id: item.id
					}
				})
			},
			// 删除健康填报
			delService(item){
				this.deleteShow = true;
				this.deleteTitle = `是否确认删除 健康填报日期为`+item.creatTime
				this.deleteId = item.id
			},
			deleteConfirm() {
				this.deleteShow = false;
				let data={
					id:this.deleteId
				}
				api.getReportRemove(data).then(res => {
					if (res.data.code == 200) {
						this.pageNum=1
						this.serviceList=[]
						this.num=null
						this.getServiceList()
						setTimeout(() => {
							uni.$u.toast('删除成功')
						}, 300)
					}
				}).catch(err => {
					uni.$u.toast(err.msg)
				})
			},
			onReachBottom() {
				// 触底的时候请求数据，即为上拉加载更多
				if(this.pageNum<=this.num){
					this.getServiceList()
				}
			},
			// 下拉刷新
			onPullDownRefresh() {
				const _that=this
				_that.pageNum=1
				_that.serviceList=[]
				_that.num=null
				_that.empty=false
				_that.deleteShow=false
				setTimeout(function () {
					uni.stopPullDownRefresh();
					_that.getServiceList();
				}, 500);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		width: calc(100% - 32rpx);
		padding: 16rpx;
		.tabsContent {
			width: 100%;
			background-color: #FFFFFF;
			height: 1000rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.formBox {
			width: calc(100% - 64rpx);
			padding: 16rpx 32rpx;
			border-radius: 8rpx;
			background-color: #FFFFFF;
			margin: 16rpx 0;
			.visitor-num{
				font-size: 28rpx;
				font-weight: bold;
				margin-bottom: 10rpx;
			}
			.line-btn{
				justify-content: space-around;
			}
			.line {
				display: flex;
				width: 100%;
				height: 60rpx;
				line-height: 60rpx;
		
				.line-title {
					width: 200rpx;
					font-size: 28rpx;
		
				}
			}
		}
		.bottomBtn{
			position: fixed;
			width: calc(100% - 63rpx) ;
			padding: 32rpx;
			bottom: 0;
			left: 0;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			box-shadow: 0rpx 1rpx 8rpx 0rpx #e5e5e5;
		}
	}
</style>
